<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'financialPledge.label', default: 'FinancialPledge')}"/>
    <title>应收账款</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>
                        <span>CINDATA PLS</span>
                    </li>
                    <li class="active">
                        <span>应收账款</span>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="index" class="form-horizontal" role="form" id="form">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" onclick="text()"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>
                <div class="panel-body seach-group" id="bug1">
                    %{--第一行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label for="city" class="col-sm-3 control-label">城市</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="city" id="city"
                                          from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}"
                                          valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                                          value="${params?.city}"
                                          noSelection="${["-1": '请选择城市']}"/>
                                <input type="hidden" id="communityId" value="${params?.communityId}" name="communityId" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" >押品风险</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="risk" id="risk"
                                          from="${com.cindata.dimension.RiskDimension.list()}"
                                          valueMessagePrefix="status" optionKey="label" optionValue="label"
                                          value="${params?.risk}"
                                          noSelection="${["": '请选择押品风险']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">押品状态</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="estateStatus" id="estateStatus"
                                          from="${com.cindata.dictionary.EstateStatusDict.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.estateStatus}"
                                          noSelection="${["": '请选择押品状态']}"/>
                            </div>
                        </div>
                    </div>
                    %{--第二行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label  class="col-sm-3 control-label">质押品名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="name" id="name" value="${params?.name}" placeholder="请输入押品名称">
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">质押品类型</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="type" id="type"
                                          from="${com.cindata.dictionary.AccountsReceivableTypeDict.listOrderById()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.type}"
                                          noSelection="${["": '请选择质押品类型']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">变现能力</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="cashability" id="cashability"
                                          from="${com.cindata.dictionary.Cashability.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.cashability}"
                                          noSelection="${["": '请选择变现能力']}"/>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </g:form>
    </div>

    <div class="row">
        <div class="hpanel hgreen">

            <div class="panel-heading">
                <div class="panel-tools">
                    <g:link action="create" class="btn btn-info btn-xs"><i class="fa fa-plus"></i>新建</g:link>
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                全部押品
            </div>

            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="esateTable">
                        <thead>
                        <tr>
                            <th style="width: 60px;"><input type="checkbox" class="i-checks allCheckbox" id="allOptionId"></th>
                            <g:sortableColumn property="externalId" title="质押品编号"  params="${params}"/>
                            <g:sortableColumn property="type" title="质押品类型"  params="${params}"/>
                            <g:sortableColumn property="estateStatus" title="押品状态"  params="${params}"/>
                            <g:sortableColumn property="name" title="质押品名称"  params="${params}"/>
                            <g:sortableColumn property="city" title="城市"  params="${params}"/>
                            <g:sortableColumn property="fullName" title="出质人名称"  params="${params}"/>
                            <g:sortableColumn property="commonOwnerFullName" title="其他共同所有人"  params="${params}"/>
                            <g:sortableColumn property="registerFullName" title="登记人"   params="${params}"/>
                            <g:sortableColumn property="registerAccount" title="登记机构"    params="${params}"/>
                            <g:sortableColumn property="registerDate" title="登记日期"    params="${params}"/>
                            <g:sortableColumn property="cashability" title="变现能力"   params="${params}"/>
                            %{--<g:sortableColumn property="mortgageStatus" title="贷款状态"   params="${params}"/>--}%
                            <g:sortableColumn property="latestEvaluatePrice" title="最新评估价值"   params="${params}"/>
                            <g:sortableColumn property="latestEvaluateDate" title="最新评估日期"   params="${params}"/>
                            <g:sortableColumn property="cltv" title="押品风险"  params="${params}"/>
                            <th style="color: #34495e;">操作项</th>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${collateralList}">
                            <tr>
                                <td><input type="checkbox" class="i-checks everyCheckbox" name="everyCheckbox" value="${it?.id}"></td>
                                <td ><g:link style="color: #3498DB" class="firstTd" action="show" id="${it?.id}">${it?.externalId}</g:link></td>
                                <td>${it?.accountsReceivable?.type?.name}</td>
                                <td>${it?.estateStatus?.name}</td>
                                <td>${it?.name}</td>
                                <td>${it?.city?.name}</td>
                                <td>${it?.fullName}</td>
                                <td>${it?.commonOwnerFullName}</td>
                                <td>${it?.registerFullName}</td>
                                <td>${it?.registerAccount}</td>
                                <td>${it?.registerDate}</td>
                                <td>${it?.cashability?.name}</td>
                                %{--<td>${it?.financialPledge?.mortgageStatus?.name}</td>--}%
                                <td>${it?.latestEvaluatePrice}</td>
                                <td>
                                    <g:if test="${it?.latestEvaluateDate}">
                                        <g:formatDate date="${it?.latestEvaluateDate}" format="yyyy-MM-dd"></g:formatDate>
                                    </g:if>
                                </td>
                                <td>
                                    <g:if test="${it?.cltv>=0&&it?.cltv<=0.6}">低</g:if>
                                    <g:if test="${it?.cltv>0.6&&it?.cltv<=0.8}">中</g:if>
                                    <g:if test="${it?.cltv>0.8&&it?.cltv<=1}">高</g:if>
                                    <g:if test="${it?.cltv>1}">损失</g:if>
                                </td>
                                <td>
                                    <div style="margin-bottom: 2px;">
                                        <a href="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                            评估
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="index" total="${collateralCount ?: 0}" params="${params}"/>
                </div>
                <div style="display: flex;justify-content: center;">
                    <button type="button" class="btn w-xs btn-success warningButton">批量评估</button>
                    <button type="button" class="btn w-xs btn-default cancelButton" style="margin-left: 20px;">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>

<g:javascript>
    var checkAll =$('.allCheckbox');  //全选的input
    var checkboxs =$('.everyCheckbox'); //所有单选的input

    checkAll.on('ifChecked ifUnchecked',function(event){
        if(event.type == 'ifChecked'){
            checkboxs.iCheck('check');
        }else{
            checkboxs.iCheck('uncheck');
        }
    });

    checkboxs.on('ifChanged',function(event){
        if(checkboxs.filter(':checked').length == checkboxs.length){
            checkAll.prop('checked',true);
        }else{
            checkAll.prop('checked',false);
        }
        checkAll.iCheck('update');
    });
    //单条评估
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
            title: "确定评估该押品吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
                function(){
                    $.ajax({
                        url:'/valuationHistory/evaluate',
                        data:{
                            ids:id,
                            sourceClass: 'accountsReceivable'
                        },
                        type:"post",
                        success:function(data)
                        {
                            if(data.status=="success"){
                                window.location.href="/accountsReceivable/index"
                            }else{
                                swal("评估失败，请稍后重试", "", "error");
                            }
                        }
                    })

                });
    });
    //多条评估
    $(".warningButton").click(function(){
        var ids = $("input:checkbox[name='everyCheckbox']:checked").map(function(index,elem) {
            return $(elem).val();
        }).get().join(',');
        if(!ids){
            toastr.error('请选择押品！');
            return
        }
        swal({
            title: "确定评估该押品吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
                function(){
                    $.ajax({
                        url:'/valuationHistory/evaluate',
                        data:{
                            ids:ids,
                            sourceClass: 'accountsReceivable'
                        },
                        type:"post",
                        success:function(data)
                        {
                            if(data.status=="success"){
                                window.location.href="/accountsReceivable/index"
                            }else{
                                swal("评估失败，请稍后重试", "", "error");
                            }
                        }
                    })
                });
    });
    //取消按钮事件
    $(".cancelButton").click(function(){
        checkboxs.iCheck('uncheck');
    });
    function searchMap() {
        var city = $("#city").val();
        if(city=="-1"){
            toastr.error('请选择城市');
            return
        }
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
    function show(id){
        var url = window.location.origin+"/accountsReceivable/show?id="+id;
        window.open(url);
    }
    $(function () {
        $('#datepicker').datepicker({
            language: 'zh-CN'
        });
        $("#datepicker").on("changeDate", function(event) {
            $("#my_hidden_input").val(
                    $("#datepicker").datepicker('getFormattedDate')
            )
        });

        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#communityId").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $('#s2id_estateStatus span:first').html('请选择押品状态');
        $('#estateStatus').val('');
        $("#name").val("");
        $('#s2id_risk span:first').html('请选择押品风险');
        $('#risk').val("");
        $('#s2id_mortgageStatus span:first').html('请选择贷款状态');
        $('#mortgageStatus').val("");
        $('#s2id_type span:first').html('请选择质押品类型');
        $('#type').val("");;
        $('#s2id_cashability span:first').html('请选择变现能力');
        $("#cashability").val("")
    });
</g:javascript>

</body>
</html>
